package com.wenwei.paper.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.paper.R;
import com.wenwei.paper.base.Constant;
import com.wenwei.paper.bean.AddGoodsListBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/13.
 */
public class ReplenishmentAdapter extends RecyclerView.Adapter<ReplenishmentAdapter.MyViewHolder> {

    private CallBack mCallBack;
    private Context mContext;
    private ArrayList<AddGoodsListBean> mList;

    public void setDataList(ArrayList<AddGoodsListBean> list) {
        this.mList = list;
    }

    public ReplenishmentAdapter(CallBack callBack) {
        this.mCallBack = callBack;
    }

    public interface CallBack {
        void onItemClick(int devicelistId,int num);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_replenishment, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallBack != null) {
                    mCallBack.onItemClick(mList.get(position).getDevicelistId(),mList.get(position).getNum());
                }
            }
        });

        Glide.with(mContext).load(Constant.BASE_IMG_URL+mList.get(position).getGoods_img()).into(holder.addGoodsImg);
        holder.addGoodsName.setText(mList.get(position).getGoods_name());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.add_goods_img)
        ImageView addGoodsImg;
        @Bind(R.id.add_goods_name)
        TextView addGoodsName;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
